#!/usr/bin/env python

import os

import webapp2
from google.appengine.ext.webapp import template
from google.appengine.api import mail

class MainPage(webapp2.RequestHandler):
    def get(self):

        test = 'ok'
        template_values = {
            'test': test
        }

        path = os.path.join(os.path.dirname(__file__), 'templates/index.html')
        self.response.write(template.render(path, template_values))

class Send(webapp2.RequestHandler):
    def post(self):
        name = self.request.get("name")
        address = self.request.get("address")
        desc = self.request.get("desc")
        url = self.request.get("url")

        sender_address = "Agences Economiques <blind1009@gmail.com>"
        subject = "Demande d'ajout d'agence"
        body = """
        Nom de l'agence : %s
        Addresse : %s
        Description : %s
        Site web : %s""" % (name, address, desc, url)

        mail.send_mail(sender_address, "vincentvitre@gmail.com", subject, body)


app = webapp2.WSGIApplication([
    ('/', MainPage),
    ('/send', Send)
], debug=True)